package function;

/**
 * @Description TODO
 * @Author li
 * @Date 2022/3/11 9:07 上午
 */
public class MaxSubArray {
    public static void main(String[] args) {
        int[] a = {4,-1,2,1,-5,4};
        maxSubArray(a);
    }

    public static int maxSubArray(int[] nums) {
        int res = nums[0];
        for(int i=1;i< nums.length;i++){
            int num = nums[i - 1];
            nums[i] += Math.max(num,0);
            int a = nums[i];
            res = Math.max(a,res);
        }
        return res;
    }
}
